package com.alvin.abp.common.context;


import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

import com.alvin.abp.domain.AlvinUser;

public class CurrentUserContext {

	public static AlvinUser getCurrentUser() {
		Authentication authenticate = SecurityContextHolder.getContext().getAuthentication();
		if(authenticate!=null && !isAnonymous()){
			return (AlvinUser) authenticate.getPrincipal();
		}else{
			AlvinUser user = new AlvinUser();
			user.setId(0l);
			user.setUserName("super admin");
			return user;
		}
		
	}
	
	public static boolean isAnonymous() {
		return ("anonymousUser").equals(SecurityContextHolder.getContext().getAuthentication()
				.getPrincipal());
	}
	
	public static void refreshUser() {
		Authentication authenticate = SecurityContextHolder.getContext().getAuthentication();
	}

}
